//
//  SDCompareDetecSelectReportVC.m
//  skinDetection
//
//  Created by  liangzhun on 2018/11/1.
//  Copyright © 2018年  liangzhun. All rights reserved.
//

#import "SDCompareDetecSelectReportVC.h"
#import "SDMyReportData.h"

@interface SDCompareDetecSelectReportVC ()<UIPickerViewDelegate,UIPickerViewDataSource>
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;

@end

@implementation SDCompareDetecSelectReportVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.view setHidden:YES];
    
    self.confirmBtn.layer.cornerRadius = 5.f;
    self.confirmBtn.layer.masksToBounds = YES;
    self.confirmBtn.layer.borderColor = SDMainColor.CGColor;
    self.confirmBtn.layer.borderWidth = 1.0;
    self.bottom.constant = -(SDBottom_Height + 389*SDWidth375Scale);
    
}

/**
 弹出报告的选择框
 */
- (void)presentTimeView
{
    [self.view setHidden:NO];
    [UIView animateWithDuration:0.3 animations:^{
        self.bottom.constant = -SDBottom_Height;
         [self.view layoutIfNeeded];
    }];
   
}

/**
 移除报告选择框
 */
- (void)dismissTimeView
{
    [UIView animateWithDuration:0.15 animations:^{
       self.bottom.constant = -(SDBottom_Height + 389*SDWidth375Scale);
         [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        [self.view setHidden:YES];
    }];
  
}
//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
//    [self presentTimeView];
//}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)confirmReport:(UIButton *)sender {
    
    if (self.selectBlock) {
        self.selectBlock(self.selectRow);
        [self dismissTimeView];
    }
}

- (IBAction)close:(UIButton *)sender {
    [self dismissTimeView];
}
#pragma mark - UIPickerViewDataSource
- (NSInteger)numberOfComponentsInPickerView:(nonnull UIPickerView *)pickerView {
    return 1;
}

- (NSInteger)pickerView:(nonnull UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return self.dateArray.count;
}
#pragma mark - UIPickerViewDelegate
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    return SDMainScreenWidth;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 40;
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    UILabel *lab = [[UILabel alloc] init];
    for (UIView *view in self.reportPickerView.subviews) {
        if (CGRectGetHeight(view.frame) < 1.0) {
            [view setBackgroundColor:RGBA(236, 236, 236, 1)];
        }
    }
    UIColor *textColor = row == self.selectRow? SDMainColor:SDMainGrayColor;
    SDMyReportData *data = self.dateArray[row];
    NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:data.createTime attributes:@{NSForegroundColorAttributeName:textColor}];
    [att addAttribute:NSFontAttributeName value:Font(15) range:NSMakeRange(0, att.length)];
    lab.textAlignment = NSTextAlignmentCenter;
    lab.attributedText = att;
    return lab;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.selectRow = row;
   
}
- (void)setSelectRow:(NSInteger)selectRow
{
    _selectRow = selectRow;
    [self.reportPickerView selectRow:selectRow inComponent:0 animated:YES];
     [self.reportPickerView reloadAllComponents];
}
@end
